#ifndef __LRUCACHE__HH__
#define __LRUCACHE__HH__

#include "../HONG.hh"
#include <unordered_map>
#include <list>
#include <string>




using std::unordered_map;
using std::list;
using std::string;
using std::pair;


class LRUCache
{
    friend void swapCache(LRUCache& lhs, LRUCache& rhs);
public:
    LRUCache(size_t capacity = CACHE_SIZE);
    LRUCache(const LRUCache& cache);
    
    void addElement(const string& key, const string& json);
    void addElement(LRUCache& rhs);

    void readFromFile(const string& filename);
    void writeToFile(const string& filename);

    bool find(const string& key, string& json);

    const list<pair<string, string>>& getResultList();

    
private:
    size_t _capacity;
    unordered_map<string, list<pair<string, string>>::iterator> _cache;   // 查询的词, 在list中的位置
    list<pair<string, string>> _resultList; // 查询的词, 推荐的词的json
};

void swapCache(LRUCache& lhs, LRUCache& rhs);

#endif